From b7a339b8502db02b2b313f53b5a1430d56efcbcb Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 9 Dec 2014 10:50:06 -0800 Subject: [PATCH] Remove lots of no longer necessary + Send annotations --- src/cargo/util/errors.rs | 67 ++++++++++++++++++++-------------------- src/cargo/util/result.rs | 12 +++---- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index fa215d4bb..935a8ef4b 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -21,7 +21,7 @@ pub trait CargoError: Send { ConcreteCargoError { description: self.description(), detail: self.detail(), - cause: self.cause().map(|c| box c.concrete() as Box), + cause: self.cause().map(|c| box c.concrete() as Box), is_human: self.is_human() } } @@ -31,9 +31,9 @@ pub trait FromError { fn from_error(error: E) -> Self; } -impl FromError for Box { - fn from_error(error: E) -> Box { - box error as Box +impl FromError for Box { + fn from_error(error: E) -> Box { + box error as Box } } @@ -47,14 +47,14 @@ macro_rules! from_error ( } ) -impl Show for Box { +impl Show for Box { fn fmt(&self, f: &mut Formatter) -> fmt::Result { try!(write!(f, "{}", self.description())); Ok(()) } } -impl CargoError for Box { +impl CargoError for Box { fn description(&self) -> String { (**self).description() } fn detail(&self) -> Option { (**self).detail() } fn cause(&self) -> Option<&CargoError> { (**self).cause() } @@ -67,30 +67,30 @@ impl CargoError for semver::ReqParseError { } } -pub type CargoResult = Result>; +pub type CargoResult = Result>; pub trait BoxError { fn box_error(self) -> CargoResult; } pub trait ChainError { - fn chain_error(self, callback: || -> E) -> CargoResult ; + fn chain_error(self, callback: || -> E) -> CargoResult ; } impl<'a, T> ChainError for ||:'a -> CargoResult { - fn chain_error(self, callback: || -> E) -> CargoResult { + fn chain_error(self, callback: || -> E) -> CargoResult { self().map_err(|err| callback().concrete().with_cause(err)) } } -impl BoxError for Result { +impl BoxError for Result { fn box_error(self) -> CargoResult { - self.map_err(|err| box err as Box) + self.map_err(|err| box err as Box) } } -impl ChainError for Result { - fn chain_error(self, callback: || -> E) -> CargoResult { +impl ChainError for Result { + fn chain_error(self, callback: || -> E) -> CargoResult { self.map_err(|err| callback().concrete().with_cause(err)) } } @@ -132,7 +132,7 @@ pub struct ProcessError { pub exit: Option, pub output: Option, pub detail: Option, - pub cause: Option> + pub cause: Option> } from_error!(ProcessError) @@ -192,20 +192,19 @@ impl CargoError for ProcessError { pub struct ConcreteCargoError { description: String, detail: Option, - cause: Option>, + cause: Option>, is_human: bool } impl ConcreteCargoError { - pub fn with_cause(mut self, - err: E) -> Box { - self.cause = Some(box err as Box); - box self as Box + pub fn with_cause(mut self, err: E) -> Box { + self.cause = Some(box err as Box); + box self as Box } - pub fn mark_human(mut self) -> Box { + pub fn mark_human(mut self) -> Box { self.is_human = true; - box self as Box + box self as Box } } @@ -237,7 +236,7 @@ pub type CliResult = Result; #[deriving(Show)] pub struct CliError { - pub error: Box, + pub error: Box, pub unknown: bool, pub exit_code: uint } @@ -291,11 +290,11 @@ impl CliError { } pub fn from_error(error: E, code: uint) -> CliError { - let error = box error as Box; + let error = box error as Box; CliError::from_boxed(error, code) } - pub fn from_boxed(error: Box, code: uint) -> CliError { + pub fn from_boxed(error: Box, code: uint) -> CliError { let human = error.is_human(); CliError { error: error, exit_code: code, unknown: !human } } @@ -310,43 +309,43 @@ pub fn process_error(msg: S, exit: status.map(|o| o.clone()), output: output.map(|o| o.clone()), detail: None, - cause: cause.map(|c| box c as Box) + cause: cause.map(|c| box c as Box) } } pub fn internal_error(error: S1, - detail: S2) -> Box { + detail: S2) -> Box { box ConcreteCargoError { description: error.as_slice().to_string(), detail: Some(detail.as_slice().to_string()), cause: None, is_human: false - } as Box + } as Box } -pub fn internal(error: S) -> Box { +pub fn internal(error: S) -> Box { box ConcreteCargoError { description: error.to_string(), detail: None, cause: None, is_human: false - } as Box + } as Box } -pub fn human(error: S) -> Box { +pub fn human(error: S) -> Box { box ConcreteCargoError { description: error.to_string(), detail: None, cause: None, is_human: true - } as Box + } as Box } -pub fn caused_human(error: S, cause: E) -> Box { +pub fn caused_human(error: S, cause: E) -> Box { box ConcreteCargoError { description: error.to_string(), detail: None, - cause: Some(box cause as Box), + cause: Some(box cause as Box), is_human: true - } as Box + } as Box } diff --git a/src/cargo/util/result.rs b/src/cargo/util/result.rs index e415f7288..aeaa9645b 100644 --- a/src/cargo/util/result.rs +++ b/src/cargo/util/result.rs @@ -1,11 +1,11 @@ use util::errors::{CargoResult, CargoError}; pub trait Wrap { - fn wrap(self, error: E) -> Self; + fn wrap(self, error: E) -> Self; } -impl Wrap for Result> { - fn wrap(self, error: E) -> CargoResult { +impl Wrap for Result> { + fn wrap(self, error: E) -> CargoResult { match self { Ok(x) => Ok(x), Err(e) => Err(error.concrete().with_cause(e)) @@ -14,14 +14,14 @@ impl Wrap for Result> { } pub trait Require { - fn require(self, err: || -> E) -> CargoResult; + fn require(self, err: || -> E) -> CargoResult; } impl Require for Option { - fn require(self, err: || -> E) -> CargoResult { + fn require(self, err: || -> E) -> CargoResult { match self { Some(x) => Ok(x), - None => Err(box err().concrete() as Box) + None => Err(box err().concrete() as Box) } } } -- 2.30.2